/**
 * Created by sakuri on 2017/4/12
 */
;-function (window) {
    "use strict";
    //TODO 预设变量写这里，全局变量写在base.js 里面 使用 r. 调用
    var ready = {
        short_name: null,
        map_chart: null,
        _right_sum_chart: null,
        _right_judge_chart: null,
        index_court: null,
        point_basic: 1
    };
    var index_option = {
        /**
         * 设置隐藏地图法院级别
         * 例如 hide_map_level = 1 在1级法院首页隐藏地图
         * hide_map_level = 3 在3级法院首页隐藏地图
         */
        hide_map_level: 3
    };
    //TODO 初始化的方法写这里面
    var init = function () {
        index.draw();//绘制页面
        init_ready();//加载预设变量
        index.init_total();//初始化顶部统计栏
        index.init_uri();//初始化链接
        // index.init_case_today();//初始化左侧列表数据
        index.init_map();//初始化页面地图
        index.init_sum_court_open();//初始化右侧开庭数与时长数据
        // index.init_judge();//初始化右侧法官开庭情况
        init_event();

        function init_event() {//TODO 初始化页面事件
            $(window).resize(function () {
                index.draw();
            });
            $('.cmp-center-left-back').click(function () {
                base.back();
            });
            $('.cmp-center-map-back').click(function () {
                base.back();
            });
            var now = new Date();
            var now_day_span = $('.cmp-right-time-count').find('.cmp-right-time');
            now_day_span.eq(0).html(now.getFullYear() + '年1月1日');
            now_day_span.eq(2).html(now.getFullYear() + '年' + (now.getMonth() + 1) + '月' + now.getDate() + '日');
            if (now.getMonth() >= 10) {
                var month = (now.getMonth() + 1);
            } else {
                var month = "0" + (now.getMonth() + 1);
            }
            if (now.getDate() >= 10) {
                var day = now.getDate();
            } else {
                var day = "0" + now.getDate();
            }
            var startDate = now.getFullYear() + "-01-01";
            var endDate = now.getFullYear() + "-" + month + "-" + day;
            if (r.level != 3) {
                $('.cmp-center-left-back').hide();
            }
            $('#judge_trial_url').attr('href', r.base_path + 'judge_Info/judge_count_info?courtUid=' + r.court_uid + "&startDate=" + startDate + "&endDate=" + endDate);
        }

        function init_ready() {//TODO 初始化预设值
            ready.map_chart = echarts.init(document.getElementById('cmp-center-map-local'));
            ready._right_sum_chart = echarts.init(document.getElementById('right-tab-1'));
            ready._right_judge_chart = echarts.init(document.getElementById('judge_div'));
            utils.set_cookie("_search", 1);
            var court_basic = base.get_court(r.court_uid);
            ready.short_name = court_basic.shortname;
        }
    };
    //TODO 内部调用的方法写这里
    var index = {
            draw: function () {
                //随着窗口大小改变 动态计算布局
                //设置第一块高度
                var window_height = $(window).height();
                var index_left_height = window_height - 280;
                $('#cmp-left-tabs-content').css('height', index_left_height + 'px');
                //设置第一块内元素边距
                var left_media_item_width = $('.cmp-left-media-item').actual('width');
                var left_item_width = left_media_item_width - 220;
                $('.cmp-left-media-item-content').css('width', left_item_width + 'px');
                var left_tab = ['left-tab-1', 'left-tab-2', 'left-tab-3'];
                $(left_tab).each(function (index, tab_id) {
                    var tab = $('#' + tab_id);
                    var tabs_li = tab.find('.media-list li');//获取所有条目
                    var tabs_li_height = (index_left_height - 44) / 5;//计算每条所占大小
                    if (tabs_li_height > 180) {//实际高度不能超过 180
                        tabs_li_height = 180;
                    }
                    tabs_li.css('height', tabs_li_height + 'px');//设置条目高度
                    var tabs_li_div_height = tab.find('.cmp-left-media-item').eq(0).actual('height');//实际高度
                    tabs_li.find('.cmp-left-media-item').css('margin-top', ((tabs_li_height - 20 - tabs_li_div_height ) / 2) + 'px');//每条目所占高度减去实际高度 等于边距高度
                });
                $('.media-list-with-divider').css('height', index_left_height - 40 + 'px');

                if (r.level == index_option.hide_map_level) {
                    var left_col = $('.cmp-center-left-col');
                    left_col.removeClass('col-md-4');
                    left_col.addClass('col-md-8');
                }
                //设置第二块高度
                var index_center_height = window_height - 284;
                var cmp_center_map = $('#cmp-center-map');
                cmp_center_map.css('height', index_center_height + 'px');
                var cmp_center_map_local_height = cmp_center_map.width() * 1.1;
                var cmp_center_map_local = $('#cmp-center-map-local');
                cmp_center_map_local.css('height', cmp_center_map_local_height + 'px');
                cmp_center_map_local.css('top', (index_center_height - cmp_center_map_local_height) / 2 + 'px');
                //设置第三块高度
                var index_right_height = window_height - 284;
                $('#cmp-right').css('height', index_right_height + 'px');
            },
            init_total: function () {
                setInterval(function () {
                    var anime = index.show_anime(50);
                    // var cmp_index_top_panel_all_span = $('.cmp_index_top_panel span');
                    //
                    // cmp_index_top_panel_all_span.removeClass('animation-restore');
                    // cmp_index_top_panel_all_span.addClass('animation-iceland');
                    $.get(r.base_path + 'index/selectIndexTopStatistical', {
                        courtUid: r.court_uid
                    }, function (result) {
                        if (result.data) {
                            setTimeout(function () {
                                anime.close();
                                // var cmp_index_top_panel_all = $('.cmp_index_top_panel .cmp-plugins-count');
                                // cmp_index_top_panel_all.addClass('animated flipInX');
                                // setTimeout(function(){
                                //     cmp_index_top_panel_all.removeClass('flipInX');
                                // }, 1000);
                                // cmp_index_top_panel_all_span.removeClass('animation-iceland');
                                //总容量
                                $('.cmp-right-fileSizeTotal').html(parseInt(result.data.countFileSize));
                                //总时长
                                $('.cmp-right-openCourtTimeTotal').html(result.data.openCourtTimeTotal);
                                index.show(result.data);
                                // cmp_index_top_panel_all_span.addClass('animation-restore');
                            }, 1000);//1秒后加载 后续优化可以去除
                        }
                    }, 'JSON');
                }, 60000);
                // total();

            },
            show: function (data) {
                //法庭总数
                var court_room_total_arr = index.format(4, data.courtNum);
                var cmp_plugins_title_court = $('.cmp-plugins-title-court span');
                cmp_plugins_title_court.eq(0).html(court_room_total_arr[0]);
                cmp_plugins_title_court.eq(1).html(court_room_total_arr[1]);
                cmp_plugins_title_court.eq(2).html(court_room_total_arr[2]);
                cmp_plugins_title_court.eq(3).html(court_room_total_arr[3]);
                //科技法庭数
                var technology_court_total_arr = index.format(4, data.technologyCourtTotal);
                var cmp_plugins_title_courtTotal = $('.cmp-plugins-title-courtTotal span');
                cmp_plugins_title_courtTotal.eq(0).html(technology_court_total_arr[0]);
                cmp_plugins_title_courtTotal.eq(1).html(technology_court_total_arr[1]);
                cmp_plugins_title_courtTotal.eq(2).html(technology_court_total_arr[2]);
                cmp_plugins_title_courtTotal.eq(3).html(technology_court_total_arr[3]);
                //平台接入
                var technology_court_technologyCourtTotal_arr = index.format(4, data.thirdCourtNum);
                var cmp_plugins_title_technologyCourtTotal = $('.cmp-plugins-title-technologyCourtTotal span');
                cmp_plugins_title_technologyCourtTotal.eq(0).html(technology_court_technologyCourtTotal_arr[0]);
                cmp_plugins_title_technologyCourtTotal.eq(1).html(technology_court_technologyCourtTotal_arr[1]);
                cmp_plugins_title_technologyCourtTotal.eq(2).html(technology_court_technologyCourtTotal_arr[2]);
                cmp_plugins_title_technologyCourtTotal.eq(3).html(technology_court_technologyCourtTotal_arr[3]);
                //排期总数
                var technology_court_courtPlan_arr = index.format(6, data.countPlan);
                var cmp_plugins_title_courtPlan = $('.cmp-plugins-title-courtPlan span');
                cmp_plugins_title_courtPlan.eq(0).html(technology_court_courtPlan_arr[0]);
                cmp_plugins_title_courtPlan.eq(1).html(technology_court_courtPlan_arr[1]);
                cmp_plugins_title_courtPlan.eq(2).html(technology_court_courtPlan_arr[2]);
                cmp_plugins_title_courtPlan.eq(3).html(technology_court_courtPlan_arr[3]);
                cmp_plugins_title_courtPlan.eq(4).html(technology_court_courtPlan_arr[4]);
                cmp_plugins_title_courtPlan.eq(5).html(technology_court_courtPlan_arr[5]);
                //开庭总数
                var closed_court_total_arr = index.format(6, data.countOpenCourtNum);
                var cmp_plugins_title_closed_span = $('.cmp-plugins-title-closed span');
                cmp_plugins_title_closed_span.eq(0).html(closed_court_total_arr[0]);
                cmp_plugins_title_closed_span.eq(1).html(closed_court_total_arr[1]);
                cmp_plugins_title_closed_span.eq(2).html(closed_court_total_arr[2]);
                cmp_plugins_title_closed_span.eq(3).html(closed_court_total_arr[3]);
                cmp_plugins_title_closed_span.eq(4).html(closed_court_total_arr[4]);
                cmp_plugins_title_closed_span.eq(5).html(closed_court_total_arr[5]);
                //正在开庭数
                var open_court_time_total_arr = index.format(4, data.countCourtNowTotal);
                var cmp_plugins_title_open_court = $('.cmp-plugins-title-open-court span');
                cmp_plugins_title_open_court.eq(0).html(open_court_time_total_arr[0]);
                cmp_plugins_title_open_court.eq(1).html(open_court_time_total_arr[1]);
                cmp_plugins_title_open_court.eq(2).html(open_court_time_total_arr[2]);
                cmp_plugins_title_open_court.eq(3).html(open_court_time_total_arr[3]);
            },
            /**
             * 将数据拆分，转换成4位字符串数组，不足补0。
             * @param size
             * @param num 需要转换的数据
             * @return [*] 4位字符数组
             */
            format: function (size, num) {
                var result_arr = [];
                for (var x = 0; x < size; x++) {
                    result_arr.push('0')
                }
                if (!num) {
                    return result_arr;
                }
                num = num + '';
                var num_arr = num.split('');
                for (var i = size, j = size - 1; i > -1; i--) {
                    if (num_arr[i]) {
                        result_arr[j] = num_arr[i];
                        j--;
                    }
                }
                return result_arr;
            },
            show_anime: function (delaytime) {
                if (!delaytime) {
                    delaytime = 100;
                }
                var anime_it = setInterval(function () {
                    var data = {};
                    data.courtNum = get_random_arr();
                    data.technologyCourtTotal = get_random_arr();
                    data.thirdCourtNum = get_random_arr();
                    data.countCourtNowTotal = get_random_arr();
                    data.countPlan = get_random_arr();
                    data.countOpenCourtNum = get_random_arr();
                    index.show(data);
                }, delaytime);
                return {
                    close: function () {
                        clearInterval(anime_it);
                    }
                };

                function get_random_arr() {
                    return Math.floor(Math.random() * 1000000000000);
                }
            },
            init_uri: function () {
                var cmp_center_map = $('#cmp-center-map');
                cmp_center_map.find('.cmp-center-map-bottom span').eq(0).html(r.court_name);
                cmp_center_map.find('.cmp-center-map-bottom span').eq(0).click(function () {
                    window.location.href = r.base_path + 'local_index?courtUid=' + r.court_uid;
                });
                if (r.court_uid !== "1300") {
                    cmp_center_map.find('.cmp-center-map-bottom p').eq(1).hide();
                    cmp_center_map.find('.cmp-center-map-bottom p').eq(2).hide();
                    cmp_center_map.find('.cmp-center-map-bottom p').eq(3).hide();
                } else {
                    cmp_center_map.find('.cmp-center-map-bottom p').eq(1).click(function () {
                        window.location.href = r.base_path + 'index?courtUid=1314';
                    });
                    cmp_center_map.find('.cmp-center-map-bottom p').eq(2).click(function () {
                        window.location.href = r.base_path + 'index?courtUid=1518';
                    });
                    cmp_center_map.find('.cmp-center-map-bottom p').eq(3).click(function () {
                        window.location.href = r.base_path + 'index?courtUid=1398';
                    });
                }
            },
            init_case_today: function () {
                if (r.level == index_option.hide_map_level) {
                    var left_col = $('.cmp-center-left-col');
                    left_col.removeClass('col-md-4');
                    left_col.addClass('col-md-8');
                }
                $.get(r.base_path + 'index/selectAllCase', {
                    courtId: r.court_uid,
                    day: utils.get_date(0),
                    page: 1,
                    pageSize: 5
                }, function (result) {
                    if (result && result.status == 0) {
                        if (result.data == null) {
                            console.log('无开庭')
                        }
                    }
                    var left_tab_1 = $('#left-tab-1');
                    left_tab_1.find('.media-list').empty();
                    $(result.data).each(function (index, elem) {
                        var startDate = elem.start_date.substring(0, elem.start_date.length - 5);
                        var uri = encodeURI(r.base_path + "views/system_monitor/living.html?uid=" + elem.uid + "&cid=" + elem.courtroom_id + "&court=" + r.court_uid + "&vc=" + elem.courtUid);
                        left_tab_1.find('.media-list').append('<li class="media media-lg">' +
                            '<a href="' + uri + '"><div class="cmp-left-media-item">' +
                            '<div class="cmp-left-media-item-img">' +
                            '<span class="cmp-left-media-item-status">' + elem.statusName + '</span>' +
                            '<img src="assets/img/list_test2.jpg"/>' +
                            '</div>' +
                            '<div class="cmp-left-media-item-content">' +
                            '<p class="cmp-left-media-item-p cmp-left-media-item-title">' + (elem.casename ? elem.casename : '未知') + '</p>' +
                            '<p class="cmp-left-media-item-p cmp-left-media-item-addr">开庭地点：' + (elem.courtroom_name ? elem.courtroom_name : '未知') + '</p>' +
                            '<p class="cmp-left-media-item-p">' +
                            '<span class="cmp-left-media-item-type">' + (elem.casetype_name ? elem.casetype_name : '未知') + '</span>' +
                            '<span class="cmp-left-media-item-time"><i class="fa fa-clock-o"></i>' + startDate + '</span>' +
                            '</p>' +
                            '</div>' +
                            '</div></a>' +
                            '</li>');
                    });
                    left_tab_1.find('.cmp-left-tabs-link a').attr('href', r.base_path + "views/more_courting.html?flag=" + 1 + "&court=" + r.court_uid);
                    index.draw();
                }, 'json').fail(function () {

                });
                $.get(r.base_path + 'index/selectAllCase', {
                    courtId: r.court_uid,
                    day: utils.get_date(1),
                    page: 1,
                    pageSize: 5
                }, function (result) {
                    var left_tab_2 = $('#left-tab-2');
                    left_tab_2.find('.media-list').empty();
                    if (result && result.status == 0) {
                        if (result.data == null) {
                            console.log('无开庭')
                        }
                    }
                    $(result.data).each(function (index, elem) {
                        var startDate = elem.start_date.substring(0, elem.start_date.length - 2);
                        var uri = encodeURI(r.base_path + "views/system_monitor/living.html?uid=" + elem.uid + "&cid=" + elem.courtroom_id + "&court=" + r.court_uid + "&vc=" + elem.courtUid);
                        left_tab_2.find('.media-list').append('<li class="media media-lg">' +
                            '<a href="' + uri + '"><div class="cmp-left-media-item">' +
                            '<div class="cmp-left-media-item-img">' +
                            '<span class="cmp-left-media-item-status">' + elem.statusName + '</span>' +
                            '<img src="assets/img/list_test2.jpg"/>' +
                            '</div>' +
                            '<div class="cmp-left-media-item-content">' +
                            '<p class="cmp-left-media-item-p cmp-left-media-item-title">' + (elem.casename ? elem.casename : '未知') + '</p>' +
                            '<p class="cmp-left-media-item-p cmp-left-media-item-addr">开庭地点：' + (elem.courtroom_name ? elem.courtroom_name : '未知') + '</p>' +
                            '<p class="cmp-left-media-item-p">' +
                            '<span class="cmp-left-media-item-type">' + (elem.casetype_name ? elem.casetype_name : '未知') + '</span>' +
                            '<span class="cmp-left-media-item-time"><i class="fa fa-clock-o"></i>' + startDate + '</span>' +
                            '</p>' +
                            '</div>' +
                            '</div></a>' +
                            '</li>');
                    });
                    left_tab_2.find('.cmp-left-tabs-link a').attr('href', r.base_path + "views/more_courting.html?flag=" + 2 + "&court=" + r.court_uid);
                    index.draw();
                }, 'json').fail(function () {

                });
                $.get(r.base_path + 'index/selectCaseInfoReview', {
                    courtId: r.court_uid,
                    start: 0,
                    pageSize: 5
                }, function (result) {
                    var left_tab_3 = $('#left-tab-3');
                    left_tab_3.find('.media-list').empty();
                    if (result && result.status == 0) {
                        if (result.data == null) {
                            console.log('无开庭')
                        }
                    }
                    $(result.data).each(function (index, elem) {
                        var startDate = elem.start_date.substring(0, elem.start_date.length - 2);
                        var uri = encodeURI(r.base_path + "views/system_monitor/play.html?planId=" + elem.uid + "&court=" + r.court_uid + "&vc=" + elem.courtUid);
                        left_tab_3.find('.media-list').append('<li class="media media-lg">' +
                            '<a href="' + uri + '"><div class="cmp-left-media-item">' +
                            '<div class="cmp-left-media-item-img">' +
                            '<img src="assets/img/list_test2.jpg"/>' +
                            '</div>' +
                            '<div class="cmp-left-media-item-content">' +
                            '<p class="cmp-left-media-item-p cmp-left-media-item-title">' + (elem.casename ? elem.casename : '未知') + '</p>' +
                            '<p class="cmp-left-media-item-p cmp-left-media-item-addr">开庭地点：' + (elem.courtroom_name ? elem.courtroom_name : '未知') + '</p>' +
                            '<p class="cmp-left-media-item-p">' +
                            '<span class="cmp-left-media-item-type">' + (elem.casetype_name ? elem.casetype_name : '未知') + '</span>' +
                            '<span class="cmp-left-media-item-time"><i class="fa fa-clock-o"></i>' + startDate + '</span>' +
                            '</p>' +
                            '</div>' +
                            '</div></a>' +
                            '</li>');
                    });
                    left_tab_3.find('.cmp-left-tabs-link a').attr('href', r.base_path + "views/more_reviewing.html?court=" + r.court_uid);
                    index.draw();
                }, 'json').fail(function () {

                });
            },
            init_map_point: function (geo) {
                // console.info(geo);
                var option = {
                    series: [{
                        name: '定位',
                        type: 'effectScatter',
                        coordinateSystem: 'geo',
                        data: index.convert_data(geo),
                        symbolSize: function (val) {
                            // console.log(val[2]);
                            return (val[2] / ready.point_basic) * 40 + 10;
                        },
                        showEffectOn: 'render',
                        rippleEffect: {
                            brushType: 'stroke'
                        },
                        hoverAnimation: true,
                        itemStyle: {
                            normal: {
                                color: '#FF7F50',
                                fontSize: 16,
                                shadowBlur: 20,
                                shadowColor: '#FF7F50'
                            }
                        },
                        zlevel: 1
                    }, {
                        name: '点',
                        type: 'scatter',
                        coordinateSystem: 'geo',
                        symbol: 'pin',
                        symbolSize: function (val) {
                            // console.log(val);
                            return (val[2] / ready.point_basic) * 40 + 30;
                        },
                        label: {
                            normal: {
                                show: true,
                                textStyle: {
                                    fontSize: 18,
                                    color: '#000'
                                },
                                formatter: function (param) {
                                    return param.value[2];
                                }
                            }
                        },
                        itemStyle: {
                            normal: {
                                color: '#fff', //标志颜色
                                borderColor: "#fff",
                                borderWidth: 2
                            },
                            emphasis: {
                                borderColor: '#fff',
                                borderWidth: 2
                            }
                        },
                        zlevel: 6,
                        data: index.convert_data(geo)
                    }]

                };
                if (ready.map_chart.getOption()) {
                    ready.map_chart.setOption(option);
                } else {
                    index.init_map(option)
                }


            },
            init_map: function (option) {
                if (r.level == index_option.hide_map_level || !r.level) {
                    $('.cmp-center-map-col').hide();
                    var right = $('.cmp-right-col');
                    right.removeClass('col-md-6');
                    right.addClass('col-md-12');
                    $('.cmp-right-time').hide();
                    var cr = $('.cmp-center-right-col');
                    cr.removeClass('col-md-8');
                    cr.addClass('col-md-4');
                    return;
                }
                var court = base.get_court(r.court_uid);
                $.get(r.base_path + "assets/plugins/echart/json/" + court.code + ".json", function (json) {
                    echarts.registerMap(json, json);
                    var base_option = {
                        tooltip: {
                            show: true,
                            trigger: 'item',
                            formatter: "{b}"
                        },
                        geo: {
                            map: json,
                            roam: false,
                            layoutCenter: ['50%', '50%'],
                            layoutSize: $('#cmp-center-map-local').width(),
                            label: {
                                normal: {
                                    show: true,
                                    textStyle: {
                                        color: '#04272f',
                                        fontSize: 18
                                    }
                                },
                                emphasis: {
                                    show: true,
                                    borderWidth: 5,
                                    textStyle: {
                                        color: '#04272f',
                                        fontSize: 22
                                    }
                                }
                            },
                            itemStyle: {
                                normal: {
                                    areaColor: '#49b9e8',
                                    borderColor: '#111'
                                },
                                emphasis: {
                                    areaColor: '#11d6c9'
                                }
                            }
                        },
                        series: [{
                            type: 'scatter',
                            left: "1%",
                            top: "1%",
                            right: "1%",
                            bottom: "1%",
                            // color:'#FF7F50',
                            label: {
                                normal: {
                                    // show: true,
                                    textStyle: {
                                        color: '#FF7F50'
                                    }
                                },
                                emphasis: {
                                    textStyle: {
                                        color: '#FF7F50'
                                    }
                                }
                            },
                            // symbol:"pin",
                            coordinateSystem: 'geo'
                        }]

                    };
                    ready.map_chart.setOption(base_option);
                    if (option) {
                        ready.map_chart.setOption(option, false, false);
                    }
                    ready.map_chart.on('click', function (param) {
                        console.log(param);
                        if (param.componentType == 'series') {
                            console.log(param.value[3]);
                            window.location.href = r.base_path + 'index?courtUid=' + param.value[3];
                        }
                        if (param.componentType == "geo") {
                            var cityName = ["福州市", "厦门市", "莆田市", "三明市", "泉州市", "漳州市", "南平市", "宁德市", "龙岩市", "厦门海事法院", "福州铁路运输法院"];
                            var cityCode = ['1301', '1315', '1325', '1332', '1345', '1357', '1369', '1380', '1390', '1398', '1518'];
                            if (cityName.indexOf(param.name) > -1) {
                                window.location.href = r.base_path + 'index?courtUid=' + cityCode[cityName.indexOf(param.name)];
                            } else {
                                r.level == 1 ? param.name = param.name + "市" : "";
                                $.each(r.court_list,function(index,elem){
                                    if(elem.parentUid == r.court_uid && elem.name.indexOf(param.name.substring(0,param.name.length - 1)) > -1){
                                        window.location.href = r.base_path + 'index?courtUid=' + elem.uid;
                                    }
                                });
                            }
                        }
                    });
                    ready.map_chart.on('mouseover', function (param) {
                        if (param && param.name === '福州市') {
                            var pingtan = $('.cmp-center-map-pingtan span');
                            pingtan.addClass('cmp-center-map-pingtan-mouseover');
                        }
                    });
                    ready.map_chart.on('mouseout', function (param) {
                        if (param && param.name === '福州市') {
                            var pingtan = $('.cmp-center-map-pingtan span');
                            pingtan.removeClass('cmp-center-map-pingtan-mouseover');
                        }
                    });
                    if (r.court_uid == '1300') {
                        $('.cmp-center-map-pingtan').addClass('cmp-center-map-pingtan-show');
                    }
                    if (r.court_uid == r.user_court_uid) {
                        $('.cmp-center-map-back').hide();
                    }
                });
            },
            init_sum_court_open: function () {
                var _nowyear = new Date();
                var nowyear = _nowyear.getFullYear() + "-01-01";
                var court_data = [];
                $('#loading').show();
                $.get(r.base_path + 'index/initSumCount', {
                    courtUid: r.court_uid,
                    startDate: nowyear,
                    endDate: utils.get_date(0),
                    status: 1
                }, function (result) {
                    if (result && result.code == 0) {
                        // console.log(result.data);
                    }
                    var type = ["刑事", "民事", "行政", "执行", "信访", "其他"];
                    var num = [0, 0, 0, 0, 0, 0];
                    //按类型开庭次数
                    // var court_total = 0;
                    $(result.data.sumOpen).each(function (i, n) {
                        // court_total = court_total + (n.count ? n.count : 0);
                        if (n.name == "赔偿") {
                            num[type.indexOf("行政")] = num[type.indexOf("行政")] + n.count;
                        } else {
                            n ? (type.indexOf(n.name) >= 0 ? num[type.indexOf(n.name)] = num[type.indexOf(n.name)] + n.count : "") : "";
                        }
                    });
                    // $('.cmp-right-count').html(court_total);

                    var a_href = ['a1', 'a2', 'a5', 'a3', 'a6', 'a7'];
                    $(type).each(function (index) {
                        var cmp_right = $('#cmp-right');
                        cmp_right.find('.cmp-right-type-item-num').eq(index).html(num[index]);
                        cmp_right.find('.cmp-right-type-item').eq(index).click(function () {
                            window.location.href = r.base_path + 'case_count/open_court_number_count?casetype=' + a_href[index] + '&courtUid=' + r.court_uid;
                        });
                    });

                    //各地开庭数与开庭时长
                    var courtUids = [];
                    //构建显示法院列表
                    $(result.data.sumOpenGroup).each(function (index, elem) {
                        if (courtUids.indexOf(elem.courtUid) == -1) {
                            courtUids.push(elem.courtUid);
                        }
                    });

                    //地图坐标相关参数
                    var geoCoordMap = [];
                    $(result.data.lags).each(function (index, elem) {
                        var tempCourtUid = {};
                        tempCourtUid.courtUid = elem.courtUid;
                        tempCourtUid.lng = elem.lng;
                        tempCourtUid.lat = elem.lat;
                        tempCourtUid.courtName = elem.courtName;
                        geoCoordMap.push(tempCourtUid);
                    });
                    // console.log(geoCoordMap);
                    $(courtUids).each(function (index, ele) {
                        //开庭总数
                        var total = 0;
                        var temp = {};
                        temp["courtUid"] = ele;
                        $(type).each(function (index, elem) {
                            temp[elem] = 0;
                        });
                        $(result.data.sumOpenGroup).each(function (index, elem) {
                            // console.log(elem);
                            if (ele == elem.courtUid) {
                                temp["courtName"] = elem.courtName;
                                $(elem.data).each(function (index, eleme) {
                                    total = total + eleme.count;
                                    if ("未知" == eleme.typeName) {
                                        temp["其他"] = temp["其他"] + eleme.count;
                                    } else if (elem.typeName == "赔偿") {
                                        temp["行政"] = temp["行政"] + eleme.count;
                                    } else {
                                        temp[eleme.typeName] = temp[eleme.typeName] + eleme.count;
                                    }
                                });
                            }
                        });
                        //循环开庭时长
                        var time_total = 0;
                        $(result.data.countTime).each(function (index, elem) {
                            if (ele == elem.courtUid) {
                                temp["courtName"] = elem.courtName;
                                $(elem.data).each(function (index, eleme) {
                                    time_total = (time_total * 10 + eleme.timeLong * 10) / 10;
                                    if ("未知" == eleme.typeName) {
                                        temp["其他时长"] = (temp["其他"] * 10 + eleme.timeLong * 10) / 10;
                                    } else {
                                        temp[eleme.typeName + '时长'] = (temp[eleme.typeName] * 10 + eleme.timeLong * 10) / 10;
                                    }
                                });
                            }
                        });
                        temp["total"] = total;
                        temp["time_total"] = time_total;
                        court_data.push(temp);
                    });
                    court_data.sort(function compare(a, b) {
                        return b.total - a.total;
                    });
                    var xAxis = [];
                    var yAxis = [];
                    var aAxis = [];
                    var timeAxis = [];
                    // console.log(court_data,geoCoordMap);
                    //根据法院循环构建开庭次数 时长表格
                    $(court_data).each(function (index, elem) {
                        xAxis.push(elem.courtName);
                        aAxis.push(elem.courtUid);
                        yAxis.push(elem.total);
                        $(geoCoordMap).each(function (geo_index, geo) {
                            if (geo.courtUid == elem.courtUid) {
                                geo.total = elem.total;
                                elem.total > ready.point_basic ? ready.point_basic = elem.total : '';
                            }
                        });
                        timeAxis.push(elem.time_total);
                    });
                    index.init_map_point(geoCoordMap);
                    var option = {
                        // tooltip: {
                        //     show: true,
                        //     trigger: 'axis',
                        //     formatter: '{b}<br/>{a}: {c}',
                        //     axisPointer: {
                        //         type: 'shadow'
                        //     }
                        // },
                        tooltip: {
                            padding: 10,
                            backgroundColor: '#222',
                            borderColor: '#777',
                            borderWidth: 1,
                            formatter: function (obj) {
                                return '<div style="border-bottom: 1px solid rgba(255,255,255,.3); font-size: 18px;padding-bottom: 7px;margin-bottom: 7px">' +
                                    obj.seriesName + '</div><span style="font-size: 18px">' +
                                    obj.name + ':' + obj.data.value + (obj.seriesIndex == 0 ? ' 次' : ' h</span>');
                            }
                        },
                        grid: [{
                            show: false,
                            left: '6%',
                            top: 10,
                            bottom: 0,
                            containLabel: true,
                            width: '45%'
                        }, {
                            show: false,
                            left: '51.5%',
                            top: 30,
                            bottom: 0,
                            width: '4%'
                        }, {
                            show: false,
                            right: '6%',
                            top: 10,
                            bottom: 0,
                            containLabel: true,
                            width: '45%'
                        }],
                        xAxis: [{
                            type: 'value',
                            inverse: true,
                            axisLine: {show: false},
                            axisTick: {show: false},
                            position: 'top',
                            axisLabel: {
                                show: true,
                                textStyle: {color: '#ddd', fontSize: 14},
                                formatter: function (value) {
                                    return value + '次'
                                }
                            },
                            splitNumber: 4,
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: '#888', width: 1,
                                    type: 'dashed'
                                }
                            }
                        }, {
                            gridIndex: 1,
                            show: false
                        }, {
                            gridIndex: 2,
                            type: 'value',
                            axisLine: {show: false},
                            axisTick: {show: false},
                            position: 'top',
                            axisLabel: {
                                show: true,
                                textStyle: {color: '#ddd', fontSize: 14},
                                formatter: function (value) {
                                    return value + 'h'
                                }
                            },
                            splitNumber: 4,
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: '#888', width: 1,
                                    type: 'dashed'
                                }
                            }
                        }
                        ],
                        yAxis: [
                            {
                                type: 'category',
                                inverse: true,
                                position: 'right',
                                axisLine: {show: false},
                                axisTick: {show: false},
                                axisLabel: {
                                    show: false,
                                    margin: 8,
                                    textStyle: {
                                        color: '#ddd', fontSize: 14
                                    }

                                },
                                data: xAxis
                            }, {
                                gridIndex: 1,
                                type: 'category',
                                inverse: true,
                                position: 'left',
                                axisLine: {show: false},
                                axisTick: {show: false},
                                axisLabel: {
                                    show: true,
                                    textStyle: {
                                        color: '#ddd', fontSize: 14
                                    }

                                },
                                data: xAxis.map(function (value) {
                                    return {
                                        value: value,
                                        textStyle: {
                                            align: 'center',
                                            fontSize: 16
                                            // fontWeight:'bold'
                                        }
                                    }
                                })
                            }, {
                                gridIndex: 2,
                                type: 'category',
                                inverse: true,
                                position: 'left',
                                axisLine: {show: false},
                                axisTick: {show: false},
                                axisLabel: {
                                    show: false,
                                    textStyle: {
                                        color: '#ddd', fontSize: 16
                                    }
                                },
                                data: xAxis
                            }
                        ],
                        series: [
                            {
                                name: '开庭次数(次)',
                                type: 'bar',
                                barGap: 20,
                                barWidth: 20,
                                label: {
                                    normal: {
                                        show: true,
                                        position: 'left',
                                        textStyle: {
                                            color: "#ffffff",
                                            fontSize: 16
                                        }
                                    },
                                    emphasis: {
                                        show: true,
                                        position: 'left',
                                        offset: [0, 0],
                                        textStyle: {color: '#fff', fontSize: 16}
                                    }
                                },
                                itemStyle: {
                                    normal: {
                                        color: '#e7b533'
                                    },
                                    emphasis: {
                                        color: '#08C7AE'
                                    }
                                },
                                data: index.convert_sum(aAxis, yAxis)
                            }, {
                                name: '开庭时长(小时)',
                                type: 'bar',
                                barGap: 20,
                                barWidth: 20,
                                xAxisIndex: 2,
                                yAxisIndex: 2,
                                label: {
                                    normal: {
                                        show: true,
                                        position: 'right',
                                        textStyle: {
                                            color: "#ffffff",
                                            fontSize: 16
                                        }
                                    },
                                    emphasis: {
                                        show: true,
                                        position: 'right',
                                        offset: [0, 0],
                                        textStyle: {color: '#fff', fontSize: 16}
                                    }
                                },
                                itemStyle: {
                                    normal: {
                                        color: '#e55e31'
                                    },
                                    emphasis: {
                                        color: '#08C7AE'
                                    }
                                },
                                data: index.convert_sum(aAxis, timeAxis)
                            }
                        ]
                    };
                    ready._right_sum_chart.setOption(option);
                    ready._right_sum_chart.on('click', function (param) {
                        if (param.seriesIndex == 0) {
                            window.location.href = r.base_path + "case_count/open_court_number_count?courtUid=" + param.data.name;
                        } else if (param.seriesIndex == 1) {
                            window.location.href = r.base_path + "case_count/open_court_time_count?courtUid=" + param.data.name;
                        }

                        // return;
                    });
                    window.onresize = ready._right_sum_chart.resize;


                    var technologyCount = result.data.technologyCount.sort(function compare(a, b) {
                        return b.rate - a.rate;
                    });
                    $(technologyCount).each(function (index, elem) {
                        var progress_bar_width = elem.rate * 0.8 + 20;
                        var html = '<a href="' + r.base_path + 'case_count/technology_court_rate?courtUid=' + elem.courtUid + '">' +
                            '<div class="cmp-right-tab-2-bucket">' +
                            '<span style="">' + elem.name + '</span>' +
                            '<div class="progress" style="">' +
                            '<div class="progress-bar" style="width: ' + progress_bar_width + '%"><span>' + elem.num + '/' + elem.totalNum + '</span></div>' +
                            '</div>' +
                            '</div>' +
                            '</a>';
                        $('#right-tab-2').append(html);
                    });
                    $('#loading').hide();
                }, 'json').fail(function () {
                    $('#loading').hide();
                    //请求失败
                });
            },
            init_judge: function (timeAndNumList) {
                var _nowyear = new Date();
                var nowyear = _nowyear.getFullYear() + "-01-01";
                // $.get(r.base_path + 'index/findJudgeTrialNumber', {
                //     courtId: r.court_uid,
                //     start: nowyear,
                //     end: utils.get_date(0)
                // }, function (result) {
                var point_max = 1;

                var colors = ['#CCFF66', '#9900cc', '#009933', '#00CC33', '#CCFF66', '#FF0033',
                    '#CC6666', '#FF3300', '#FF6600', '#FF9900', '#FFCC66', '#FF9966',
                    '#FF6666', '#FF66CC', '#CCFFCC', '#CCCCCC', '#CC99CC'];
                var series = [];
                var courts = [];
                if (r.level == 1) {
                    $(timeAndNumList).each(function (index, elem) {
                        elem.openTime > point_max ? point_max = elem.openTime : '';
                        if (courts.indexOf(elem.courtUid.substr(0, 2)) == -1) {
                            courts.push(elem.courtUid.substr(0, 2));
                        }
                    });
                } else {
                    $(timeAndNumList).each(function (index, elem) {
                        elem.openTime > point_max ? point_max = elem.openTime : '';
                        if (courts.indexOf(elem.courtUid.substr(0, 3)) == -1) {
                            courts.push(elem.courtUid.substr(0, 3));
                        }
                    });
                }
                $(courts).each(function (i, elem) {
                    var series_one = {
                        name: '开庭次数',
                        data: index.convert_judge(timeAndNumList, elem),
                        type: 'scatter',
                        symbolSize: function (data) {
                            return (data[1] / point_max) * 25 + 10;
                        },
                        label: {
                            emphasis: {
                                show: true,
                                formatter: function (param) {
                                    return param.data[2];
                                },
                                position: 'top'
                            }
                        },
                        itemStyle: {
                            normal: {
                                color: colors[i]
                            }
                        }
                    };
                    series.push(series_one);
                });
                var option = {
                    grid: [{
                        show: false,
                        left: '9%',
                        right: '6%',
                        top: 30,
                        bottom: 20
                    }],
                    tooltip: {
                        padding: 10,
                        backgroundColor: '#222',
                        borderColor: '#777',
                        borderWidth: 1,
                        formatter: function (obj) {
                            var value = obj.value;
                            return '<div style="border-bottom: 1px solid rgba(255,255,255,.3); font-size: 18px;padding-bottom: 7px;margin-bottom: 7px">' +
                                '法院：' + value[3] + '<br>姓名：' + value[2] +
                                '</div>' +
                                '开庭次数：' + value[0] + '次<br>' +
                                '开庭时长：' + value[1] + '小时<br>';
                        }
                    },
                    xAxis: {
                        splitLine: {
                            show: false
                        },
                        axisLine: {
                            lineStyle: {
                                color: '#fff'
                            }
                        },
                        axisLabel: {
                            formatter: function (value) {
                                return value + '次'
                            }
                        }
                    },
                    yAxis: {
                        nameTextStyle: {
                            color: '#fff',
                            fontSize: 16
                        },
                        splitNumber: 4,
                        axisLine: {
                            lineStyle: {
                                color: '#eee',
                                show: false
                            }
                        },
                        axisLabel: {
                            formatter: function (value) {
                                return value + 'h'
                            }
                        },
                        splitLine: {
                            show: false
                        },
                        scale: true
                    },

                    series: series
                };
                ready._right_judge_chart.setOption(option);
                window.onresize = ready._right_judge_chart.resize;
                // }, 'json').fail(function () {
                //
                // });
            },
            convert_data: function (data) {
                // console.log(typeof data,data);
                var res = [];
                $(data).each(function (index, elem) {
                    res.push({
                        name: elem.courtName,
                        value: [parseFloat(elem.lng), parseFloat(elem.lat), elem.total, elem.courtUid],
                        color: '#FF7F50',
                        itemStyle: {
                            normal: {
                                textStyle: {
                                    fontSize: 16,
                                    color: (elem.total > 100 ? '#FF7F50' : '#000')
                                }
                            },
                            emphasis: {
                                textStyle: {
                                    color: (elem.total > 100 ? '#FF7F50' : '#000')
                                }
                            }
                        }
                    });
                });
                // console.log(res);
                return res;
            },
            convert_sum: function (data, axis) {
                var res = [];
                for (var i = 0; i < data.length; i++) {
                    res.push({
                        name: data[i],
                        value: axis[i]
                    });
                }
                return res;
            },
            convert_judge: function (data, type_court) {
                var res = [];
                $(data).each(function (index, elem) {
                    var judge_sum = [];
                    if (r.level == 1) {
                        if (type_court == elem.courtUid.substr(0, 2)) {
                            judge_sum.push(elem.openNum);
                            judge_sum.push(elem.openTime);
                            judge_sum.push(elem.realName);
                            judge_sum.push(elem.courtName);
                            res.push(judge_sum);
                        }
                    } else {
                        if (type_court == elem.courtUid.substr(0, 3)) {
                            judge_sum.push(elem.openNum);
                            judge_sum.push(elem.openTime);
                            judge_sum.push(elem.realName);
                            judge_sum.push(elem.courtName);
                            res.push(judge_sum);
                        }
                    }

                });
                return res;
            }
        };
    init();
    //TODO 对外公开的方法写在这里
    window.p = {
        draw: index.draw,
        show: index.show,
        anime: index.show_anime,
        initJudge: index.init_judge
    };
}(window);


